package GUILayer;

import javax.swing.*;

import java.awt.Font;
import java.text.DecimalFormat;

import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;

import CtrLayer.CtrApartment;
import CtrLayer.CtrContract;
import CtrLayer.CtrRentalPayment;
import CtrLayer.CtrTenant;
import java.awt.Color;

public class DashboardGUI {

	CtrTenant ctrTenant;
	CtrContract ctrContract;
	CtrApartment ctrApartment;
	CtrRentalPayment ctrRenPay;
	
	JPanel mainPanel;
	DecimalFormat df = new DecimalFormat("#,###,##0.00");
	
	public DashboardGUI() {
		ctrTenant = new CtrTenant();
		ctrContract = new CtrContract();
		ctrApartment = new CtrApartment();
		ctrRenPay = new CtrRentalPayment();
		
		initialize();
	}
	
	public JPanel getPanel() {
		return mainPanel;
	}
	
	private Font fontLabel = new Font("Verdana", Font.PLAIN, 13);
	private Font fontValue = new Font("Verdana", Font.BOLD, 13);
	
	
	private void initialize() 
	{
		mainPanel = new JPanel();
		mainPanel.setLayout(null);
		
		JPanel summaryPanel = new JPanel();
		summaryPanel.setBounds(261, 171, 400, 311);
		mainPanel.add(summaryPanel);
		
		
		JLabel ffTenantsArrear = new JLabel(""+ctrTenant.getTenantsInArrear());
		ffTenantsArrear.setHorizontalAlignment(SwingConstants.RIGHT);
		ffTenantsArrear.setFont(fontValue);
		
		JLabel lblTenantsArrear = new JLabel("Tenants in arrears (R"+df.format(ctrTenant.geTenantsInArrear_Money())+")");
		lblTenantsArrear.setFont(fontLabel);
		
		
		
		JLabel ffContrExp = new JLabel(""+ctrContract.getContractsExpiringThisMonth());
		ffContrExp.setHorizontalAlignment(SwingConstants.RIGHT);
		ffContrExp.setFont(fontValue);
		
		JLabel lblContrExp = new JLabel("Contracts expiring this month");
		lblContrExp.setFont(fontLabel);
		
		
		
		
		JLabel ffContrExp2M = new JLabel(""+ctrContract.getContractsExpiringNextTwoMonths());
		ffContrExp2M.setHorizontalAlignment(SwingConstants.RIGHT);
		ffContrExp2M.setFont(fontValue);
		
		JLabel lblContrExp2M = new JLabel("Contracts expiring next 2 months");
		lblContrExp2M.setFont(fontLabel);
		

		
		
		JLabel lblPropWT = new JLabel("Properties without tenants");
		lblPropWT.setFont(fontLabel);
		
		JLabel ffPropWT = new JLabel(""+ctrApartment.getPropertiesWithoutTenants());
		ffPropWT.setHorizontalAlignment(SwingConstants.RIGHT);
		ffPropWT.setFont(fontValue);
		
		
		
		JLabel lblProperties = new JLabel("Properties");
		lblProperties.setFont(fontLabel);
		
		JLabel ffProperties = new JLabel(""+ctrApartment.getProperties());
		ffProperties.setHorizontalAlignment(SwingConstants.RIGHT);
		ffProperties.setFont(fontValue);
		
		
		
		
		JLabel ffActiveTenants = new JLabel(""+ctrTenant.getActiveTenants());
		ffActiveTenants.setHorizontalAlignment(SwingConstants.RIGHT);
		ffActiveTenants.setFont(fontValue);
		
		JLabel lblActiveTenants = new JLabel("Active Tenants");
		lblActiveTenants.setFont(fontLabel);
		
		
		
		
		JLabel lblCommissionLastMonth = new JLabel("Commission last month");
		lblCommissionLastMonth.setFont(fontLabel);
		
		JLabel ffCommissionLastMonth = new JLabel("R"+df.format(ctrRenPay.getCommissionLastMonth()));
		ffCommissionLastMonth.setHorizontalAlignment(SwingConstants.RIGHT);
		ffCommissionLastMonth.setFont(fontValue);
		
		
		
		
		JLabel lblCommissionThisMonth = new JLabel("Commission this month");
		lblCommissionThisMonth.setFont(fontLabel);
		
		JLabel ffCommissionThisMonth = new JLabel("R"+df.format(ctrRenPay.getCommissionThisMonth()));
		ffCommissionThisMonth.setHorizontalAlignment(SwingConstants.RIGHT);
		ffCommissionThisMonth.setFont(fontValue);
		
		
		
		
		JLabel ffReceiveActTenants = new JLabel("R"+df.format(ctrRenPay.getReceivable()));
		ffReceiveActTenants.setHorizontalAlignment(SwingConstants.RIGHT);
		ffReceiveActTenants.setFont(fontValue);
		
		JLabel lblReceivableFromActive = new JLabel("Receivable from active tenants");
		lblReceivableFromActive.setFont(fontLabel);
		
		
		
		
		GroupLayout gl_summaryPanel = new GroupLayout(summaryPanel);
		gl_summaryPanel.setHorizontalGroup(
			gl_summaryPanel.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_summaryPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_summaryPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(ffCommissionThisMonth, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
						.addComponent(ffReceiveActTenants, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
						.addGroup(gl_summaryPanel.createParallelGroup(Alignment.TRAILING)
							.addComponent(ffProperties, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(ffActiveTenants, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(ffPropWT, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(ffCommissionLastMonth, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE))
						.addComponent(ffContrExp, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
						.addComponent(ffContrExp2M, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
						.addComponent(ffTenantsArrear, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE))
					.addPreferredGap(ComponentPlacement.RELATED, 29, GroupLayout.PREFERRED_SIZE)
					.addGroup(gl_summaryPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(lblTenantsArrear, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
						.addComponent(lblProperties, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
						.addComponent(lblContrExp, GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
						.addComponent(lblContrExp2M, GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
						.addComponent(lblActiveTenants, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
						.addGroup(gl_summaryPanel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_summaryPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(lblReceivableFromActive, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
								.addComponent(lblCommissionThisMonth, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
								.addComponent(lblCommissionLastMonth, GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
							)
						)
						.addComponent(lblPropWT, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
					)
					.addContainerGap()
				)
		);
		
		gl_summaryPanel.setVerticalGroup(
			gl_summaryPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_summaryPanel.createSequentialGroup()
					.addGap(5)
					.addGroup(gl_summaryPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(ffTenantsArrear)
						.addComponent(lblTenantsArrear))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_summaryPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(ffContrExp, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblContrExp, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_summaryPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblContrExp2M, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
						.addComponent(ffContrExp2M, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_summaryPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(ffPropWT, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblPropWT, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_summaryPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblProperties, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
						.addComponent(ffProperties, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_summaryPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(ffActiveTenants, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblActiveTenants, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
					.addGap(48)
					.addGroup(gl_summaryPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblCommissionLastMonth, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
						.addComponent(ffCommissionLastMonth, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_summaryPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblCommissionThisMonth, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
						.addComponent(ffCommissionThisMonth, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_summaryPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(ffReceiveActTenants, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblReceivableFromActive, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
					.addGap(159))
		);
		summaryPanel.setLayout(gl_summaryPanel);
		
		JPanel panel = new JPanel();
		panel.setBounds(249, 83, 400, 62);
		mainPanel.add(panel);
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Monthly Summary");
		lblNewLabel.setForeground(new Color(25, 25, 112));
		lblNewLabel.setFont(new Font("Verdana", Font.PLAIN, 36));
		lblNewLabel.setBounds(36, 11, 364, 51);
		panel.add(lblNewLabel);
	}
}
